#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/grid.h>

class Notebook : public wxFrame
{
public:
    Notebook(const wxString &title);

    void OnQuit(wxCommandEvent &event);
};

class MyGrid : public wxGrid
{
public:
    MyGrid(wxNotebook *parent, int nrow = 30, int ncol = 20);
};

Notebook::Notebook(const wxString &title)
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400, 350))
{

    wxNotebook *nb = new wxNotebook(this, -1, wxPoint(-1, -1),
                                    wxSize(-1, -1), wxNB_BOTTOM);

    wxMenuBar *menubar = new wxMenuBar;
    wxMenu *file = new wxMenu;
    file->Append(wxID_EXIT, wxT("Quit"), wxT(""));
    menubar->Append(file, wxT("&File"));
    SetMenuBar(menubar);

    Connect(wxEVT_COMMAND_MENU_SELECTED,
            wxCommandEventHandler(Notebook::OnQuit));

    MyGrid *grid1 = new MyGrid(nb, 10, 20);
    MyGrid *grid2 = new MyGrid(nb, 20, 30);
    MyGrid *grid3 = new MyGrid(nb, 30, 40);

    nb->AddPage(grid1, wxT("Sheet1"));
    nb->AddPage(grid2, wxT("Sheet2"));
    nb->AddPage(grid3, wxT("Sheet3"));

    CreateStatusBar();
    Center();
}

void Notebook::OnQuit(wxCommandEvent &event)
{
    Close(true);
}

MyGrid::MyGrid(wxNotebook *parent, int nrow, int ncol)
    : wxGrid(parent, wxID_ANY)
{
    CreateGrid(nrow, ncol);
    SetRowLabelSize(50);
    SetColLabelSize(25);
    SetRowLabelAlignment(wxALIGN_CENTER, wxALIGN_CENTRE);
    SetColLabelAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
    SetLabelFont(wxFont(9, wxFONTFAMILY_DEFAULT,
                        wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));

    for (int i = 0; i < nrow; i++)
    {
        this->SetRowSize(i, 25);
    }
}

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

bool MyApp::OnInit()
{
    Notebook *frame = new Notebook(wxT("Notebook"));
    frame->Show(true);
    return true;
}

wxIMPLEMENT_APP(MyApp);
